﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;



using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.IO;
using ZedGraph;

namespace weiqijiance
{
    public partial class TESTYH : Form
    {
        public string sshebei = "经济性";
        public mainform m_mainform;
        public string sdetid;
        /// <summary>
        /// 结果变量
        /// </summary>
        public float fsudu;
        public float fjiazaili;
        public float fyouhao;

        public Thread t1;
        public Thread t2;
        public string xianshineirong;
        public string businessId;
        public int xssj;
        油耗仪.yhbass yhcomm = new 油耗仪.yhbass();


        public int iYHHWQ;//油耗到位红外

        public int iYHKZJSS;//油耗举升升
        public int iYHKZJSJ;//油耗举升降

        public int iYHtdz;//油耗信号左通道
        public int iYHtdy;//油耗信号右通道
        public int iYHtdh;//油耗信号右通道

        public int iYHSDtd;//油耗信号接在那个通道
        public int iFENGSHAN = -1;////测功机风扇

        float[] m_YH = new float[900];
        float[] m_ShuDu = new float[900];
        float[] m_Li = new float[900];
        public float fyhxz;//油耗限值


        //红外取反
        public bool[] bhongwaiqf = new bool[16] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };//红外是否取反
        //红外定位时间
        public int[] ihongwaidwsj = new int[16] { 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 };//红外定位时间单位毫秒



        // /声明INI文件的写操作函数 WritePrivateProfileString()
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        //声明INI文件的读操作函数 GetPrivateProfileString()
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        private string sPath = null;

        public 控制流程.flowcrtl flowbass = new 控制流程.flowcrtl();
        public TESTYH(int Width, int Height)
        {
            InitializeComponent();
            panel_Width = Width;
            panel_Height = Height;
            gettongdao();
            //this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            x = this.Width;
            y = this.Height;
            setTag(this);
            xinxixianshi.Text = "燃油经济性检测";
            yhcomm.init();
            init();
        }
        public void start(string sbusinessId)
        {
            fyhxz = 0;
            businessId = sbusinessId;

            bianliangchushihua();
           
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Start();

          
        }

        public void bianliangchushihua()
        {
            fsudu = 0;
            fjiazaili = 0;

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\车辆信息.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

        }

        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            if (newy <= 0)
            {
                newy = 1;
            }
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion

        //ini文件
        public void Ini(string path)
        {
            this.sPath = path;
        }

        public void Writue(string section, string key, string value)
        {
            // section=配置节，key=键名，value=键值，path=路径
            WritePrivateProfileString(section, key, value, sPath);
        }

        public string ReadValue(string section, string key)
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节，key=键名，temp=上面，path=路径
            GetPrivateProfileString(section, key, "", temp, 255, sPath);
            return temp.ToString();
        }
        //ini文件


        private delegate void FlushClient();//代理

        private void xianshi()
        {
            if (this.xinxixianshi.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshi);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xinxixianshi.Text = string.Format(@"{0}", xianshineirong);
            }
        }

        private void xianshisudu()
        {
            if (this.gauge_speed.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshisudu);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.gauge_speed.Visible = true;
                this.digitalGauge1.DigitCount = string.Format(@"{0}", fsudu).Length < 3 ? 3 : string.Format(@"{0}", fsudu).Length;
                this.digitalGauge1.Text = string.Format(@"{0}", fsudu);
            }
        }

        private void xianshijzl()
        {
            if (this.gauge_jzl.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshijzl);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.gauge_jzl.Visible = true;
                this.digitalGauge2.DigitCount = string.Format(@"{0}", fjiazaili).Length < 3 ? 3 : string.Format(@"{0}", fjiazaili).Length;
                this.digitalGauge2.Text = string.Format(@"{0}", fjiazaili);
            }
        }

        private void xianshiyh()
        {
            if (this.gauge_yh.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiyh);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.gauge_yh.Visible = true;
                this.digitalGauge3.DigitCount = string.Format(@"{0}", yhcomm).Length < 3 ? 3 : string.Format(@"{0}", yhcomm).Length;
                this.digitalGauge3.Text = string.Format(@"{0}", yhcomm);
                //this.youhao.Text = string.Format(@"{0}", yhcomm.m_fYH);
            }
        }

        protected void thisclose()
        {

            this.Invoke(new Action(this.Close));  //使用委托关闭该窗体
        }

        public void gettongdao()
        {

            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            for (int i = 0; i < 10; i++)
            {
                string sgetname = ReadValue("通道设置", string.Format(@"模拟信号{0}", i + 1));
                if (sgetname.Contains("测功力左"))
                {
                    iYHtdz = i;
                }

                if (sgetname.Contains("测功力右"))
                {
                    iYHtdy = i;
                }

                if (sgetname.Contains("测功力后"))
                {
                    iYHtdh = i;
                }
            }

            for (int i = 0; i < 8; i++)
            {
                string smaichong = ReadValue("通道设置", string.Format(@"速度{0}", i + 1));
                if (smaichong.Contains("测功速度"))
                {
                    iYHSDtd = i;
                }

            }

            for (int i = 0; i < 16; i++)
            {
                string shongwai = ReadValue("通道设置", string.Format(@"红外{0}", i + 1));
                if (shongwai.Contains("车速到位"))
                {
                    iYHHWQ = i;
                }


                shongwai = ReadValue("通道设置", string.Format(@"红外定位时间{0}", i + 1));
                int.TryParse(shongwai, out ihongwaidwsj[i]);


                shongwai = ReadValue("通道设置", string.Format(@"红外是否取反{0}", i + 1));
                if (shongwai.Contains("是"))
                {
                    bhongwaiqf[i] = true;
                }
                else
                {
                    bhongwaiqf[i] = false;
                }
            }
            ///控制
            for (int i = 0; i < 8; i++)
            {

                string shongwai = ReadValue("通道设置", string.Format(@"控制{0}", i + 1));
                if (shongwai.Contains("测功举升升"))
                {
                    iYHKZJSS = i;
                }
                if (shongwai.Contains("测功举升降"))
                {
                    iYHKZJSJ = i;
                }
                if (shongwai.Contains("测功机风扇"))
                {
                    iFENGSHAN = i;
                }
            }
        }
        float fwd = 0;
        float fsd = 0;
        float fdqyl = 0;
        int iqsmz = 0;
        int iddzz = 0;
        int igdzz = 0;
        string sgt = "";
        public void StratTest()
        {

            //ShowControls(true);
            if (!flowbass.bJCJSSJ)
            {
                xianshineirong = string.Format(@"燃油经济性免检");
                xianshi();
                flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
                //m_mainform.WaitEventMJ(iSUHW, bhongwaiqf[iSUHW], ihongwaidwsj[iSUHW]);
                return;
            }
            flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "油耗检测开始", flowbass.sDetectID);
            myPaneex.CurveList.Clear();
            myPaneex.GraphObjList.Clear();
            zg2.AxisChange();

            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);
            string sqsmz = objini.ReadValue("油耗", "起始码值").Trim();
            string sddzz = objini.ReadValue("油耗", "低点码值自增").Trim();
            string sgdzz = objini.ReadValue("油耗", "高点码值自增").Trim();
            sgt = objini.ReadValue("油耗", "滚筒").Trim();
            xssj = 0;
            int.TryParse(objini.ReadValue("油耗", "信息显示时间"), out xssj);
            if (!int.TryParse(sqsmz, out iqsmz))
            {
                iqsmz = 800;
            }
            if (!int.TryParse(sddzz, out iddzz))
            {
                iqsmz = 40;
            }
            if (!int.TryParse(sgdzz, out igdzz))
            {
                iqsmz = 20;
            }
            List<int> listspeed = new List<int>();
            List<int> listjzl = new List<int>();
            List<int> listgl = new List<int>();
            List<int> listssyh = new List<int>();
            List<int> listCO = new List<int>();
            List<int> listHC = new List<int>();
            List<int> listCO2 = new List<int>();
            List<int> listfxxll = new List<int>();

            listspeed.Add(0);
            listgl.Add(0);
            listjzl.Add(0);
            listssyh.Add(0);
            listCO.Add(0);
            listHC.Add(0);
            listCO2.Add(0);
            listfxxll.Add(0);
            WriteGraph(myPaneex, zg2, listspeed, listjzl, listssyh, listspeed.Count);

            //public void WriteGraph(ZedGraphControl zgc, string[] sspeed, string[] sli, string[] syouhao,  int icount)
            //m_mainform.getstand(businessId);//读取限值标准
            //m_mainform.DAC.tiaoling(1);
            float fmubiaosudu = 50;//测试速度
            float fmubiaojiazaili = 500;//测试加载力

            //参数获取
            fmubiaosudu = flowbass.fmubiaosudu;
            //

            //if(m_DetInformation.m_Login.iryzl==0)
            //{
            //    Reg.SetValue("燃油","汽油"); 
            //}
            //else
            //{
            //    Reg.SetValue("燃油","柴油"); 
            //}
            //if(m_DetInformation.m_Login.fFDJPL==0)
            //    m_DetInformation.m_Login.fFDJPL=5000;
            //if(m_DetInformation.m_Login.fFDJPL<100)
            //        m_DetInformation.m_Login.fFDJPL=m_DetInformation.m_Login.fFDJPL*1000;

            //Reg.SetValue("排量",m_DetInformation.m_Login.fFDJPL); 


            //if(m_DetInformation.m_Login.bZWXLT)
            //{

            //}
            //else
            //{

            //}
            float ftc = 130f;
            if (sgt.Contains("二轴四滚"))
            {
                if (fmubiaosudu==50)
                {
                    ftc=100;
                }
                else
                {
                    ftc=110;
                }
            }
            else
            {
                if (fmubiaosudu==50)
                {
                    ftc=130;
                }
                else
                {
                    ftc=140;
                }

            }
            float ffc = flowbass.iqdzbzl * 9.8f * 1.5f * 0.006f;
            float Fc = ffc + ftc;
            float FTCJZL = flowbass.fyhfr - Fc;
            fmubiaojiazaili = FTCJZL;


            flowbass.AddData(flowbass.sDetectID, "DET_YHFTC", "Detects_SJC", ftc);//
            flowbass.AddData(flowbass.sDetectID, "DET_YHFFC", "Detects_SJC", ffc);//
            flowbass.AddData(flowbass.sDetectID, "DET_YHFC", "Detects_SJC", Fc);//
            flowbass.AddData(flowbass.sDetectID, "DET_YHJZL", "Detects_SJC", FTCJZL);//



            if (fmubiaojiazaili <= 2)
            {
                fmubiaojiazaili = 500;
            }
            if (fmubiaosudu <= 2)
            {
                fmubiaosudu = 50;
            }
            //----------------------------------------
            //   txtjiazaili.Text=fmubiaojiazaili.ToString();
            xianshijzl();
            fjiazaili = 0;
            xianshineirong = string.Format(@"经济性检测开始");
            xianshi();
            flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);



            //yhcomm.sendYHcom(0x23, 0xD3);//气体调零
            //Thread.Sleep(2000);
            //yhcomm.sendYHcom(0x0B, 0xEB);//风机流量
            yhcomm.sendYHcom(0x0C, 0xEA);//风机大流量
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x06, 0xF0);//风机启动
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x10, 0xE6);//开蹦抽气
            Thread.Sleep(2000);
            xianshineirong = string.Format(@"取环境温湿度");
            xianshi();
            flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
            for (int i = 0; i < 3; i++)
            {
                yhcomm.sendYHcom(0x00, 0xF6);//环境温湿度
                Thread.Sleep(2000);
            }
            //07H-00H-03H-F6H
            // 红外定位
            //   m_mainform.WaitEvent(iYHHWQ, bhongwaiqf[iYHHWQ], ihongwaidwsj[iYHHWQ]);

            //m_mainform.DAC.LiftTwo(false, (short)(iYHKZJSS), (short)(iYHKZJSJ));

            m_mainform.DAC.Lift(false);
            m_mainform.DAC.SetDOBit((short)iFENGSHAN, 1);
           
            // 提示
            xianshineirong = string.Format(@"请挂最高档加速到{0}并稳住...", fmubiaosudu);
            xianshi();
            string shx = string.Format(@"目标速度{0}", fmubiaosudu);
            string sxx = string.Format(@"请挂最高档");
            flowbass.LedWrite(shx, sxx, 1);
            //测量数据
            DateTime dstart = DateTime.Now;
            DateTime dstartjz = DateTime.Now;
          
           
            DateTime dstartCYZ = DateTime.Now;

            yhcomm.sendYHcom(0x70, 0x86);
            DateTime dateqx = DateTime.Now;
            for (; ; )
            {
                fsudu = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iYHSDtd]);
                xianshisudu();
                //fsudu = 50;
                xianshineirong = string.Format(@"当前速度：{0}", fsudu);
                shx = string.Format(@"目标速度{0}", fmubiaosudu);
                sxx = string.Format(@"当前速度：{0}", fsudu);
                flowbass.LedWrite(shx, sxx, 1);
                if (fsudu > 20)
                {
              
                    //fjiazaili = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iYHtdz]) + m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iYHtdy]) + m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iYHtdh]);
                    fjiazaili = (m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iYHtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iYHtdz]) + m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iYHtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iYHtdy]) + m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iYHtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iYHtdh])) * 10f;
                    fjiazaili = (float)Math.Round(fjiazaili, 0);
                    xianshijzl();
                    if ((fjiazaili >= fmubiaojiazaili - 20 && fjiazaili <= fmubiaojiazaili + 20))// || (m_mainform.DateDiff(DateTime.Now, dstartjz) > 1000 * 30))
                    {
                        break;
                    }
                    else
                    {
                        if (fjiazaili < fmubiaojiazaili - 20)
                        {
                            if (iqsmz > 1500)
                            {
                                iqsmz += igdzz;
                            }
                            else
                            {
                                iqsmz += iddzz;
                            }
                        }
                        else if (fjiazaili > fmubiaojiazaili + 20)
                        {
                            if (iqsmz > 1500)
                            {
                                iqsmz -= igdzz;
                            }
                            else
                            {
                                iqsmz -= iddzz;
                            }
                        }
                        //ishuchu++;
                       
                        m_mainform.DAC.PutVol(iqsmz);
                    }

                    listspeed.Add((int)(fsudu * 10));
                    listgl.Add((int)(fsudu * fjiazaili/3600f*10f));
                    listjzl.Add((int)fjiazaili);
                    listssyh.Add(0);
                    listCO.Add(0);
                    listHC.Add(0);
                    listCO2.Add(0);
                    listfxxll.Add(0);
                    WriteGraph(myPaneex, zg2, listspeed, listjzl, listssyh, listspeed.Count);
                    dateqx = DateTime.Now;

                }
                Thread.Sleep(800);
            }

            yhcomm.sendYHcom(0x70, 0x86);

            DateTime dstartjs = DateTime.Now;
            //力稳定后开始判断速度
            for (int k = 15; k > 0; k--)
            {
                m_mainform.DAC.PutVol(iqsmz);

                yhcomm.sendYHcom(0x70, 0x86);
                dstartjs = DateTime.Now;

                fsudu = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iYHSDtd]);
                fsudu = (float)Math.Round(fsudu, 1);
              //  fsudu = 60;//fwj//test
                fjiazaili = (m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iYHtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iYHtdz]) + m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iYHtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iYHtdy]) + m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iYHtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iYHtdh])) * 10f;
                fjiazaili = (float)Math.Round(fjiazaili, 0);
                fjiazaili = fmubiaojiazaili - 10 + m_mainform.getRandom(0, 15);
               // fjiazaili = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iYHtdz]) + m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iYHtdy]) + m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iYHtdh]);
                xianshijzl();
                if (fsudu > 20 && fsudu <= 49)
                {
                    fsudu = fsudu + 0.5f;
                }
                else if (fsudu > 51 && fsudu <= 80)
                {
                    fsudu = fsudu - 0.5f;
                }
                else if (fsudu > 49 && fsudu < 49.5)
                {
                    fsudu=49.5f;
                }
                else if (fsudu > 50.5 && fsudu <= 51)
                {
                    fsudu = 50.5f;
                }
                xianshisudu();
                //判断速度并读数，
                if ((fsudu > fmubiaosudu + 0.5) || (fsudu < fmubiaosudu - 0.5))
                {
                    k++;// = 15;//时间复位
                }
                // 提示
                xianshineirong = string.Format(@"目标速度{0} 当前{1} 剩{2}秒", fmubiaosudu, fsudu, k);
                xianshi();

                 shx = string.Format(@"目标速度{0}", fmubiaosudu);
                 sxx = string.Format(@"当前{0} 剩{1}秒",  fsudu, k);
                flowbass.LedWrite(shx, sxx, 1);
                //if (m_mainform.DateDiff(DateTime.Now, dstartjs) > 1000)
                //{
                //    break;
                //}

                listspeed.Add((int)(fsudu * 10));
                listgl.Add((int)(fsudu * fjiazaili / 360f));
                listjzl.Add((int)fjiazaili);
                //listssyh.Add((int)yhcomm.m_fYH);
                listssyh.Add((int)(yhcomm.m_fYH * 1000f));
                listCO.Add((int)(yhcomm.m_fCO*100));
                listHC.Add((int)yhcomm.m_fHC);
                listCO2.Add((int)(yhcomm.m_fCO2*100));
                listfxxll.Add((int)yhcomm.m_fXXLL);
                WriteGraph(myPaneex, zg2, listspeed, listjzl, listssyh, listspeed.Count);
                Thread.Sleep(800);

            }
            for (int i = 60; i > 0; i--)
            {
                m_mainform.DAC.PutVol(iqsmz);
                dstartjs = DateTime.Now;
                //  for (; ; )
                {
                    yhcomm.sendYHcom(0x70, 0x86);
                   

                    fsudu = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iYHSDtd]);
                    fsudu = (float)Math.Round(fsudu, 1);
                  //  fsudu = 60;//fwj
                    fjiazaili = (m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iYHtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iYHtdz]) + m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iYHtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iYHtdy]) + m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iYHtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iYHtdh])) * 10f;
                    fjiazaili = (float)Math.Round(fjiazaili, 0);
                    fjiazaili = fmubiaojiazaili - 10 + m_mainform.getRandom(0, 15);
                    // fjiazaili = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iYHtdz]) + m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iYHtdy]) + m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iYHtdh]);
                    xianshijzl();

                    if (fsudu > 20 && fsudu <= 49)
                    {
                        fsudu = fsudu + 0.5f;
                    }
                    else if (fsudu > 51 && fsudu <= 80)
                    {
                        fsudu = fsudu - 0.5f;
                    }
                    else if (fsudu > 49 && fsudu < 49.5)
                    {
                        fsudu = 49.5f;
                    }
                    else if (fsudu > 50.5 && fsudu <= 51)
                    {
                        fsudu = 50.5f;
                    }
                    xianshisudu();
                    //判断速度并读数
                    if ((fsudu > fmubiaosudu + 0.5) || (fsudu < fmubiaosudu - 0.5))
                    {
                        i++;// = 60;//时间复位
                    }
                    xianshineirong = string.Format(@"目标速度{0} 当前{1} 剩{2}秒  油耗{3}ml", fmubiaosudu, fsudu, i, yhcomm.m_fYH);
                    xianshi();
                    shx = string.Format(@"目标速度{0}剩{1}秒", fmubiaosudu, i);
                    sxx = string.Format(@"当前{0}油耗{1}", fsudu, yhcomm.m_fYH);
                    flowbass.LedWrite(shx, sxx, 1);

                    m_YH[i] = yhcomm.m_fYH*1000f;
                    m_ShuDu[i] = fsudu;
                    m_Li[i] = fjiazaili;
                    //if (m_mainform.DateDiff(DateTime.Now, dstartjs) > 1000)
                    //{
                    //    break;
                    //}

                    listspeed.Add((int)(fsudu * 10));
                    listgl.Add((int)(fsudu * fjiazaili / 360f));
                    listjzl.Add((int)fjiazaili);
                    listssyh.Add((int)(yhcomm.m_fYH * 1000f));
                    listCO.Add((int)(yhcomm.m_fCO * 100));
                    listHC.Add((int)yhcomm.m_fHC);
                    listCO2.Add((int)(yhcomm.m_fCO2 * 100));
                    listfxxll.Add((int)yhcomm.m_fXXLL);
                    //listspeed.Add(fsudu);
                    //listjzl.Add(fjiazaili);
                    //listssyh.Add(yhcomm.m_fYH);
                    //listCO.Add(yhcomm.m_fCO);
                    //listHC.Add(yhcomm.m_fHC);
                    //listCO2.Add(yhcomm.m_fCO2);
                    //listfxxll.Add(yhcomm.m_fXXLL);
                    WriteGraph(myPaneex, zg2, listspeed, listjzl, listssyh, listspeed.Count);
                    Thread.Sleep(800);
                }

            }

            shx = string.Format(@"检测完成");
            sxx = string.Format(@"请减速");
            flowbass.LedWrite(shx, sxx, 1);
            for (; ; )
            {
                if (m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iYHSDtd]) < 3)
                {
                    break;
                }
                Thread.Sleep(1);
            }
            yhcomm.sendYHcom(0x21, 0xD5);//停止
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x11, 0xE5);//反吹
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x16, 0xE0);//停止动作
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x07, 0xEF);//关闭风机
            Thread.Sleep(2000);


            /////举升上升
            
            //
            m_mainform.DAC.Lift(true);
            m_mainform.DAC.SetDOBit((short)iFENGSHAN, 0);


            float fjl = 0;
            int iyh = 0;
            for (int j = 0; j < 60; j++)
            {
                fjl = fjl + (m_ShuDu[j] / 3600);
                iyh = iyh + (int)m_YH[j];
            }
            //百公里油耗
            float fyh100 = (float)((100 / fjl) * iyh * 0.000001);
            fyh100 = (float)Math.Round(fyh100, 1);
            fyhxz = flowbass.STD_YOUHAO;

            bool bGood = true;
            if (fyh100 > fyhxz)
            {
                bGood = false;
            }
            //保存数据
            fwd = yhcomm.fwd;
            fsd = yhcomm.fsd;
            fdqyl = yhcomm.fdqy;
            flowbass.AddData(flowbass.sDetectID, "DET_YH", "Detects_SJC", fyh100);//
            flowbass.AddData(flowbass.sDetectID, "DET_YHWD", "Detects_SJC", fwd);//
            flowbass.AddData(flowbass.sDetectID, "DET_YHSD", "Detects_SJC", fsd);//
            flowbass.AddData(flowbass.sDetectID, "DET_YHDQY", "Detects_SJC", fdqyl);//

            flowbass.AddData(flowbass.sDetectID, "DET_YHJL", "Detects_SJC", bGood ? 1 : 2);//项目是否合格
            string sJGPD;
            sJGPD = string.Format("{0},{1},≤{2},{3}", "经济性(L/100 km)", fyh100, fyhxz, bGood ? "合格" : "不合格");

            flowbass.AddData(flowbass.sDetectID, "PD_RYJJX", "PD_ZJ", sJGPD);

            shx = string.Format(@"百公里油耗{0}", fyh100);
            sxx = string.Format(@"{0}", bGood ? "合格" : "不合格");
            flowbass.LedWrite(shx, sxx, 1);

            if (!bGood)
            {
                flowbass.getbuhge(flowbass.sDetectID, "RYJJX");
            }
            else
            {

                flowbass.sethege(flowbass.sDetectID, "RYJJX");
            }
            //  曲线

            //listspeed.Add(fsudu);
            //listssyh.Add(yhcomm.m_fYH);

            //listHC.Add(yhcomm.m_fHC);
            //listfxxll.Add(yhcomm.m_fXXLL);

            //功率
            //listjzl.Add(fjiazaili);

            //listCO.Add(yhcomm.m_fCO);
            //listCO2.Add(yhcomm.m_fCO2);
            flowbass.editData(flowbass.sDetectID, "DET_YHSP", "Detects_SJC", listspeed, listssyh); //  //曲线
            flowbass.editData(flowbass.sDetectID, "DET_YHL", "Detects_SJC", listgl, listjzl); //  //曲线
            flowbass.editData(flowbass.sDetectID, "DET_YHHC", "Detects_SJC", listHC, listfxxll); //  //曲线
            flowbass.editData(flowbass.sDetectID, "DET_YHCO2", "Detects_SJC", listCO, listCO2); //  //曲线
            //m_pDbCon->EditData( flowbass.sDetectID,"VAX_YH","Vaxles",(unsigned char*)m_ArrayCurve,m_uCount*2*sizeof(USHORT),0+1);//写制动曲线

            //m_pDbCon->EditData( flowbass.sDetectID,"VAX_YHHC","Vaxles",(unsigned char*)m_ArrayCurveHC,m_uCount*2*sizeof(USHORT),0+1);//写制动曲线

            //m_pDbCon->EditData( flowbass.sDetectID,"VAX_YHCO","Vaxles",(unsigned char*)m_ArrayCurveCO,m_uCount*2*sizeof(USHORT),0+1);//写制动曲线

            //m_pDbCon->EditData( flowbass.sDetectID,"VAX_YHCO2","Vaxles",(unsigned char*)m_ArrayCurveCO2,m_uCount*2*sizeof(USHORT),0+1);//写制动曲线



            xianshineirong = string.Format(@"油耗:{0}L/100 km  {1}", fyh100, bGood ? "合格" : "不合格");
            xianshi();
            Thread.Sleep(3000);
            //thisclose();
            flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "油耗检测结束", flowbass.sDetectID);
        }

        public void Thread1()
        {
            
            //try
            {
                StratTest();
                if (flowbass.LastProcessnewzj(int.Parse(flowbass.sDetectID)) && (flowbass.bzj || flowbass.bsj))
                {
                    xianshineirong = "检测线完成";
                    flowbass.UpdateLoginRecord(DateTime.Now.ToString(), "检测线完成", flowbass.sDetectID);
                    flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
                    flowbass.sethegezj(flowbass.sDetectID);
                    Thread.Sleep(2000);
                }
                Thread.Sleep(1000);
                flowbass.getProcessfinish(flowbass.sDetectID, "RYJJX");
                flowbass.LedWrite(flowbass.sgongwei, "", 1);
                xianshineirong = flowbass.sgongwei;
                xianshi();

                end(); openshangxian();
                //t1.Abort();
                //t1.DisableComObjectEagerCleanup();
            }
            //catch (Exception ex)
            //{
            //    //错误日记 记录到当天日期下目录中
            //    m_mainform.baocunriji("油耗", ex.Message.ToString());
            //}
        }
        public void Thread2()
        {
            while(true)
            {
                yhcomm.sendYHcom(0x02,0xF4);
                Thread.Sleep(300);
                xianshiyh();
            
            
            }


        }
        public int panel_Width;
        public int panel_Height;    
        private void TESTYH_Resize(object sender, EventArgs e)
        {
            //float newx = (this.Width) / x;
            //float newy = (this.Height) / y;
            //setControls(newx, newy, this);
        }

        private void btnUp_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(true);
        }

        private void btnDown_Click(object sender, EventArgs e)
        {
            ///举升下降
            m_mainform.DAC.Lift(false);
        }

        private void btnYouHaoAction_Click(object sender, EventArgs e)
        {
            yhcomm.sendYHcom(0x23, 0xD3);//气体调零
            Thread.Sleep(200);
            yhcomm.sendYHcom(0x0B, 0xEB);//风机流量
            Thread.Sleep(200);
            yhcomm.sendYHcom(0x06, 0xF0);//风机启动
            Thread.Sleep(200);
            yhcomm.sendYHcom(0x10, 0xE6);//开蹦抽气
            Thread.Sleep(200);
        }

        private void btnYaoHaoStop_Click(object sender, EventArgs e)
        {
            yhcomm.sendYHcom(0x21, 0xD5);//停止
            Thread.Sleep(200);
            yhcomm.sendYHcom(0x11, 0xE5);//反吹
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x16, 0xE0);//停止动作
            Thread.Sleep(500);
            yhcomm.sendYHcom(0x07, 0xEF);//关闭风机
            Thread.Sleep(200);
        }

        private void btnFlowsStart_Click(object sender, EventArgs e)
        {
            start("001");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (flowbass.izhuangtai == 2)
                {
                    m_mainform.objyibiaobass.select(flowbass.sshebei);
                    m_mainform.bpanelshow = true;
                    m_mainform.showpanel();
                    flowbass.izhuangtai = 1;
                    //Thread tt = new Thread(end);
                    //tt.Start();
                    flowbass.IsReadyForStart();
                    bianliangchushihua();
                    t1 = new Thread(new ThreadStart(Thread1));
                    t1.Start();
                    //this.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                m_mainform.baocunriji("油耗打开窗体失败", ex.Message.ToString());
                m_mainform.SaveErrorLog("油耗打开窗体", ex.Message.ToString());//problem
            }
        }
        public void timerstart()
        {
            timer1.Enabled = true;
        }
        public void end()
        {
            
            flowbass.izhuangtai = 0;
            flowbass.sendend("E", flowbass.sDetectID);
            //closeform();
        }

        private void closeform()
        {
            if (this.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(closeform);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.Dispose();
                this.Close();
            }
        }

        private void 仪表设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            工位配置.YHsetting obj = new 工位配置.YHsetting();
            obj.ShowDialog();
        }

        private void btnFlowsStart_Click_1(object sender, EventArgs e)
        {

            start("001");
           

        }

        private void btnYouHaoAction_Click_1(object sender, EventArgs e)
        {
            yhcomm.sendYHcom(0x23, 0xD3);//气体调零
           Thread.Sleep(2000);
            yhcomm.sendYHcom(0x0B, 0xEB);//风机流量
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x06, 0xF0);//风机启动
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x10, 0xE6);//开蹦抽气
            Thread.Sleep(2000);
        }

        private void btnUp_Click_1(object sender, EventArgs e)
        {
            //m_mainform.DAC.LiftTwo(true, (short)(iYHKZJSS), (short)(iYHKZJSJ));
            m_mainform.DAC.Lift(true);
        }

        private void btnYaoHaoStop_Click_1(object sender, EventArgs e)
        {
            yhcomm.sendYHcom(0x21, 0xD5);//停止
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x11, 0xE5);//反吹
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x16, 0xE0);//停止动作
            Thread.Sleep(2000);
            yhcomm.sendYHcom(0x07, 0xEF);//关闭风机
            //Sleep(200);

        }


        GraphPane myPaneex;
        public GraphPane WriteGraphini(ZedGraphControl zgc)
        {
            //zgc.Dispose();

            //判断每条曲线的最大值
            double ispmax = 0;
            ispmax = 100;

            double ili = 0;
            ili = 500;//ili * 1.3;


            double iyouhao = 0;
            iyouhao = 4;//iyouhao * 1.4 / 1000;

            //zgc.GraphPane.
            GraphPane myPane = zgc.GraphPane;
            zgc.IsShowPointValues = true;//数据节点
            // Set the titles and axis labels
            myPane.Title.Text = string.Format(@"燃油经济性过程曲线");
            myPane.XAxis.Title.Text = "时间, s";
            myPane.YAxis.Title.Text = "速度, km/h";
            myPane.Y2Axis.Title.Text = "油耗, mL";

            // Make up some data points based on the Sine function
            PointPairList vList = new PointPairList();
            PointPairList aList = new PointPairList();
            PointPairList dList = new PointPairList();
            PointPairList eList = new PointPairList();

            //Generate a red curve with diamond symbols, and "Velocity" in the legend
            LineItem myCurve = myPane.AddCurve("速度",
               vList, Color.Red, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Generate a blue curve with circle symbols, and "Acceleration" in the legend
            myCurve = myPane.AddCurve("油耗",
               aList, Color.Blue, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;

            // Generate a green curve with square symbols, and "Distance" in the legend
            myCurve = myPane.AddCurve("加载力",
               dList, Color.Lime, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the second Y axis
            myCurve.YAxisIndex = 1;



            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max = ispmax;//最大值
            myPane.YAxis.Scale.Min=0;// = ispmax;//最大值

            // Enable the Y2 axis display
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale blue
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            myPane.Y2Axis.Scale.Min = 0;
            myPane.Y2Axis.Scale.Max = iyouhao;

            // Create a second Y Axis, green
            YAxis yAxis3 = new YAxis("加载力");
            myPane.YAxisList.Add(yAxis3);
            //myPane.Y2AxisList
            yAxis3.Scale.FontSpec.FontColor = Color.Lime;
            yAxis3.Title.FontSpec.FontColor = Color.Lime;
            yAxis3.Color = Color.Green;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis3.MajorTic.IsInside = false;
            yAxis3.MinorTic.IsInside = false;
            yAxis3.MajorTic.IsOpposite = false;
            yAxis3.MinorTic.IsOpposite = false;
            yAxis3.Scale.Max = ili;
            yAxis3.Scale.Min = 0;
            // Align the Y2 axis labels so they are flush to the axis
            //   yAxis3.Scale.Align = AlignP.Inside;



            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);

            zgc.AxisChange();
            zgc.Invalidate();
            return myPane;
        }
        public void WriteGraph(GraphPane myPane, ZedGraphControl zgc, List<int> sspeed, List<int> sli, List<int> syouhao, int icount)
        {
            double ispmax = 0;
            for (int i = 0; i < icount; i++)
            {

                if (ispmax < (sspeed[i])*1.3f)
                {
                    ispmax = (sspeed[i]);
                }

            }

            double ili = 0;
            for (int i = 0; i < icount; i++)
            {

                if (ili < (sli[i])*1.2f)
                {
                    ili = (sli[i]);
                }

            }


            double iyouhao = 0;
            for (int i = 0; i < icount; i++)
            {

                if (iyouhao < (syouhao[i])*1.1f)
                {
                    iyouhao = (syouhao[i]);
                }

            }
            if (myPane.YAxis.Scale.Max < ispmax)
            {
                myPane.YAxis.Scale.Max = ispmax * 1.1 / 10;
            }
            if (myPane.Y2Axis.Scale.Max < iyouhao)
            {
                myPane.Y2Axis.Scale.Max = iyouhao * 1.2 / 1000;
            }
            if (myPane.YAxisList["加载力"].Scale.Max < ili*1.3f)
            {
                myPane.YAxisList["加载力"].Scale.Max = ili*1.3f;
            }
            // Make up some data points based on the Sine function
            PointPairList vList = new PointPairList();
            PointPairList aList = new PointPairList();
            PointPairList dList = new PointPairList();

            // Fabricate some data values

           
            for (int i = 0; i < icount; i++)
            {
                double time = (double)i;

                vList.Add(time, ((float)sspeed[i]) / 10f);


                aList.Add(time, (float)((float)syouhao[i])/1000f);

                dList.Add(time, (sli[i]));




            }

            // Generate a red curve with diamond symbols, and "Velocity" in the legend
            LineItem myCurve = myPane.AddCurve("",
               vList, Color.Red, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            //myCurve.Symbol.Fill = new Fill(Color.White);

            // Generate a blue curve with circle symbols, and "Acceleration" in the legend
            myCurve = myPane.AddCurve("",
               aList, Color.Blue, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            //myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;

            // Generate a green curve with square symbols, and "Distance" in the legend
            myCurve = myPane.AddCurve("",
               dList, Color.Lime, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            //myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the second Y axis
            myCurve.YAxisIndex = 1;

            zgc.AxisChange();
            zgc.Invalidate();
        }
        public void init()
        {
            myPaneex = WriteGraphini(zg2);
        }

        private void TESTYH_Resize_1(object sender, EventArgs e)
        {

            //float newx = (panel_Width) / x;
            //float newy = (panel_Height) / y;
            //setControls(newx, newy, this);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            flowbass.izhuangtai = 1;
            
            flowbass.IsReadyForStart();
            bianliangchushihua();
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Start();
        }

        private void TESTYH_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                t1.Abort();
                t1.DisableComObjectEagerCleanup();
                yhcomm.sendYHcom(0x21, 0xD5);//停止
                Thread.Sleep(2000);
                yhcomm.sendYHcom(0x11, 0xE5);//反吹
                Thread.Sleep(2000);
                yhcomm.sendYHcom(0x16, 0xE0);//停止动作
                Thread.Sleep(2000);
                yhcomm.sendYHcom(0x07, 0xEF);//关闭风机
                Thread.Sleep(2000);
            }
            catch
            { }
            flowbass.izhuangtai = 0;
            //flowbass.sendend("E", flowbass.sDetectID);
        }

        private void TESTYH_Load(object sender, EventArgs e)
        {
            
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowControls(true);
            ShowButtons(true);
        }
        public void ShowControls(bool flag)
        {
            //zg2.Visible = flag;
            groupBox1.Visible = flag;

           
            label1.Visible = flag;
            label2.Visible = flag;
            label3.Visible = flag;
            label4.Visible = flag;
            gauge_speed.Visible = flag;
            gauge_jzl.Visible = flag;
            gauge_yh.Visible = flag;
            gauge_jsjzl.Visible = flag;
        

        }
        public void ShowButtons(bool flag)
        {
            btnFlowsStart.Visible = flag;
            btnUp.Visible = flag;
            btnDown.Visible = flag;
            btnYouHaoAction.Visible = flag;
            btnYaoHaoStop.Visible = flag;
            but_tiaoling.Visible = flag;
        }

        private void but_tiaoling_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.tiaoling(1);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            start("001");
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(true);
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            ///举升下降
            m_mainform.DAC.Lift(false);
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            yhcomm.sendYHcom(0x23, 0xD3);//气体调零
            //	Sleep(200);
            yhcomm.sendYHcom(0x0B, 0xEB);//风机流量
            //Sleep(200);
            yhcomm.sendYHcom(0x06, 0xF0);//风机启动
            //Sleep(200);
            yhcomm.sendYHcom(0x10, 0xE6);//开蹦抽气
            //Sleep(200);
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            yhcomm.sendYHcom(0x21, 0xD5);//停止
            //Sleep(200);
            yhcomm.sendYHcom(0x11, 0xE5);//反吹
            //Sleep(2000);
            yhcomm.sendYHcom(0x16, 0xE0);//停止动作
            //Sleep(500);
            yhcomm.sendYHcom(0x07, 0xEF);//关闭风机
            //Sleep(200);
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.tiaoling(1);
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {

            toolStripButton7.Enabled = false;
            flowbass.izhuangtai = 1;
            //Thread tt = new Thread(end);
            //tt.Start();
            flowbass.IsReadyForStart();
            bianliangchushihua();
            // m_mainform.DAC.tiaoling(1);
            //if (flowbass.dlxsxpd(flowbass.sDetectID))
            //{
            //    if (MessageBox.Show(flowbass.sPlate + "   已经检测过动力性，是否再次检测？", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
            //    {
            //        openshangxian();
            //        return;
            //    }
            //    else
            //    {
            //        t1 = new Thread(new ThreadStart(Thread1));
            //        t1.Start();
            //    }
            //}
            //else
            //{
                t1 = new Thread(new ThreadStart(Thread1));
                t1.Start();
            //}
        }

        private void openshangxian()
        {
            if (this.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(openshangxian);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                toolStripButton7.Enabled = true;
            }
        }
        private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e)
        {

            openshangxian();
            try
            {
                t1.Abort();
                t1.DisableComObjectEagerCleanup();
            }
            catch
            { }
            flowbass.izhuangtai = 0;
            xianshineirong = string.Format(@"油耗下线");
            xianshi();
            flowbass.LedWrite(flowbass.sPlate, xianshineirong, 1);
            Thread.Sleep(1000);
            flowbass.LedWrite(flowbass.sgongwei, "", 1);
        }

        private void TESTYH_Shown(object sender, EventArgs e)
        {
            try
            {
                float newx = (this.Width) / x;
                float newy = (this.Height) / y;
                setControls(newx, newy, this);
                ShowControls(false);
                ShowButtons(false);
                this.BackgroundImage = Image.FromFile(@"./ico/经济性背景.jpg");
                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            }
            catch (Exception ex)
            {

                m_mainform.baocunriji("油耗Load失败", ex.Message.ToString());//problem
                m_mainform.SaveErrorLog("油耗Load失败", ex.Message.ToString());//problem

            }
        }
    }
}
